package com.ys.web.user.privacy;

import com.ys.base.EnumType;
import com.ys.utils.base.http.ResponseHandler;
import com.ys.utils.base.j2se.StringHandler;
import com.ys.utils.redis.Redis;
import com.ys.utils.redis.key.UserKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user/privacy/")
public class PrivacyController {
    @Autowired
    private PrivacyService privacyService;

    @RequestMapping("index")
    public String index(@RequestAttribute String uid){
        return ResponseHandler.success(privacyService.getPrivacyById(StringHandler.getLong(uid)));
    }

    @RequestMapping("/config")
    public String config(@RequestAttribute String uid,int status,int type){
        int i = privacyService.config(uid, status, type);
        if(i==1){
            String key = UserKey.getPrivacyConfigKey(StringHandler.getLong(uid));
            Redis.key.del(key);
        }
        return i==1?ResponseHandler.success():ResponseHandler.error(EnumType.ResponseCode.Fail);
    }

}
